package com.cindata
import com.cindata.dictionary.*

class ContactSurvey implements Comparable{
  // 借款人基本信息
  String fullName                     // 姓名
  String sex                          // 性别
  ContactIdentityType identityType    // 证件类型
  Date birthday                       // 出身日期
  String idNumber                     // 身份证号
  String householdType                // 户口性质
  AccountNatureDict accountNature     // 户口类型
  String cellphone                    // 联系电话
  String phone                        // 住宅电话
  BigDecimal monthlyIncome            // 月收入
  String zipCode                      // 邮编
  String address                      // 地址
  String workUnitName                 // 工作单位
  String workUnitAddress              // 工作单位地址
  String maritalStatus = "未婚"       // 婚姻状态

  //配偶
  String spouseFullName               // 配偶姓名
  String spouseCellphone                    // 配偶联系电话
  ContactIdentityType spouseIdentityType    // 配偶证件类型
  String spouseIdNumber                     // 配偶身份证号

  // 客户资信状况
  String creditOverdueRecord              // 征信逾期记录：无,1-3次，3-6次，6次以上
  String creditDefaultingRecord           // 征信违约记录：无，房贷，信用卡
  String creditSearchingTimesInHalfYear   // 近半年征信查询次数：无,1-3次，3-6次，6次以上
  //配偶资信状况
  String spouseCreditOverdueRecord              // 配偶征信逾期记录：无,1-3次，3-6次，6次以上
  String spouseCreditDefaultingRecord           // 配偶征信违约记录：无，房贷，信用卡
  String spouseCreditSearchingTimesInHalfYear   // 配偶近半年征信查询次数：无,1-3次，3-6次，6次以上

  // 负债情况
  String debtType                  // 负债类型
  Integer debtMount                // 负债笔数
  BigDecimal loansBalance          // 结余金额
  BigDecimal repaymentMountPerMon  // 月均还款额
  String memo                      // 备注
  BigDecimal overdraftAmount       // 信用卡透支金额
  BigDecimal guaranteeForOthersAmount  // 为他人债务担保综合


  // 家庭成员收入能力检查记录
  OrganizationNatureDict workUnitNature // 工作单位性质
  String workUnitPhone                  // 固定电话
  String numberCheckChannel             // 号码验证通道
  Date workUnitCheckDate                // 核查时间
  String checkContent                   // 核查提问：是否本单位职工，职工个人情况是否吻合，员工缴存情况是否与系统对应
  String checkReceiver                  // 接听人员
  String checkReceiverIdentity          // 身份
  String answeredSituation              // 答复情况：核实无误，异常
  String abnormalMeno                   // 异常原因
  String actuallyCheckSituation         // 工作单位实地核实情况

  Date fundDepositStartDate           // 起始月份
  Date fundDepositEndDate             // 截止月份
  Integer fundDepositDuration         // 连续缴存期数
  BigDecimal fundDepositAmountPerMon  // 月缴额
  BigDecimal fundDepositRatio         // 缴存比例
  BigDecimal fundDepositBaseAmount    // 月缴存基数
  String fundOpenedBank               // 公积金开户行
  BigDecimal fundBalance              // 公积金余额
  String fundAccount                  // 公积金账号

  BigDecimal monthlyTotalIncome       // 借款人月均总收入

  Date createdDate = new Date()
  Date modifiedDate = new Date()
  User user
  User createBy
  User modifyBy

  static belongsTo = [report: ContactSurveyReport]

  static mapping = {
    autowire true
  }

    static constraints = {

      fullName maxSize: 20, nullable: true, blank: true
      sex maxSize: 2, nullable: true, blank: true
      sex inList: ['男', '女']
      identityType nullable: true, blank: true
      birthday nullable: true, blank: true
      idNumber maxSize: 18, nullable: true, blank: true
      householdType maxSize: 20, nullable: true, blank: true
      accountNature nullable: true, blank: true
      cellphone maxSize: 11, nullable: true, blank: true
      phone maxSize: 20, nullable: true, blank: true
      monthlyIncome nullable: true, blank: true
      zipCode maxSize: 20, nullable: true, blank: true
      address maxSize: 150, nullable: true, blank: true
      workUnitName maxSize: 50, nullable: true, blank: true
      workUnitAddress maxSize: 150, nullable: true, blank: true
      maritalStatus maxSize: 10, nullable: true, blank: true
      //配偶
      spouseFullName maxSize: 20, nullable: true, blank: true
      spouseCellphone maxSize: 11, nullable: true, blank: true
      spouseIdentityType nullable: true, blank: true
      spouseIdNumber maxSize: 18, nullable: true, blank: true


      // 客户资信状况
      creditOverdueRecord maxSize: 20, nullable: true, blank: true
      creditOverdueRecord inList: ['无', '1-3次', '3-6次', '6次以上']
      creditDefaultingRecord maxSize: 20, nullable: true, blank: true
      creditDefaultingRecord inList: ['无', '房贷', '信用卡']
      creditSearchingTimesInHalfYear maxSize: 20, nullable: true, blank: true
      creditSearchingTimesInHalfYear  inList: ['无', '1-3次', '3-6次', '6次以上']

      // 客户配偶资信状况
      spouseCreditOverdueRecord maxSize: 20, nullable: true, blank: true
      spouseCreditOverdueRecord inList: ['无', '1-3次', '3-6次', '6次以上']
      spouseCreditDefaultingRecord maxSize: 20, nullable: true, blank: true
      spouseCreditDefaultingRecord inList: ['无', '房贷', '信用卡']
      spouseCreditSearchingTimesInHalfYear maxSize: 20, nullable: true, blank: true
      spouseCreditSearchingTimesInHalfYear inList: ['无', '1-3次', '3-6次', '6次以上']


      // 负债情况
      debtType maxSize: 20, nullable: true, blank: true
      debtMount nullable: true, blank: true
      loansBalance nullable: true, blank: true
      repaymentMountPerMon nullable: true, blank: true
      memo maxSize: 200, nullable: true, blank: true
      overdraftAmount nullable: true, blank: true
      guaranteeForOthersAmount nullable: true, blank: true

      // 家庭成员收入能力检查记录
      workUnitNature nullable: true, blank: true
      workUnitPhone maxSize: 20, nullable: true, blank: true
      numberCheckChannel maxSize: 50, nullable: true, blank: true
      workUnitCheckDate nullable: true, blank: true
      checkContent maxSize: 50, nullable: true, blank: true
      checkReceiver maxSize: 20, nullable: true, blank: true
      checkReceiverIdentity maxSize: 50, nullable: true, blank: true
      answeredSituation maxSize: 50, nullable: true, blank: true
      abnormalMeno maxSize: 200, nullable: true, blank: true
      actuallyCheckSituation maxSize: 200, nullable: true, blank: true

      fundDepositStartDate nullable: true, blank: true
      fundDepositEndDate nullable: true, blank: true
      fundDepositDuration nullable: true, blank: true
      fundDepositAmountPerMon nullable: true, blank: true
      fundDepositRatio nullable: true, blank: true
      fundDepositBaseAmount nullable: true, blank: true
      fundOpenedBank maxSize: 50, nullable: true, blank: true
      fundBalance nullable: true, blank: true
      fundAccount maxSize: 50, nullable: true, blank: true

      monthlyTotalIncome nullable: true, blank: true

      createdDate nullable: true, blank: true
      modifiedDate nullable: true, blank: true
      user nullable: true, blank: true
      createBy nullable: true, blank: true
      modifyBy nullable: true, blank: true
    }

    @Override
    int compareTo(Object contactSurvey)
    {

        def contact = (ContactSurvey) contactSurvey
        if (id == contact.id)
        {
            return 0
        }
        else if (id > contact.id)
        {
            return 1
        }
        else
        {
            return -1
        }
    }

    def springSecurityService
    def beforeInsert()
    {
        def username = springSecurityService?.getPrincipal()?.username
        createBy = User.findByUsername(username)
    }

    def beforeUpdate()
    {
        modifiedDate = new Date()
        def username = springSecurityService?.getPrincipal()?.username
        modifyBy = User.findByUsername(username)
    }
}
